package com.example.studentdemo.mapper;

import com.example.studentdemo.entity.Task;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface TaskMapper {
    List<Task> selectAll(Task task);

    void insert(Task task);

    @Select("select * from `task` where name = #{name}")
    Task selectByName(String name);

    void updateById(Task task);

    @Delete("delete from `task` where id = #{id}")
    void deleteById(Integer id);

    @Select("select * from `task` where id = #{id}")
    Task selectById(Integer id);

    @Select("select * from `task` where subject_id = #{subjectId}")
    List<Task> selectBySubjectId(Integer subjectId);

    @Select("select t.*, s.name as subjectName from `task` t join `subject` s on t.subject_id = s.id where s.teacher_id = #{teacherId}")
    List<Task> selectByTeacherId(Integer teacherId);

    @Select("select t.*, s.name as subjectName from `task` t join `subject` s on t.subject_id = s.id join subject_student ss on s.id = ss.subject_id where ss.student_id = #{studentId}")
    List<Task> selectByStudentId(Integer studentId);
}